package com.djf.djfauth.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.djf.djfauth.entity.UserAuth;
import com.djf.djfauth.mapper.UserAuthMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author 26393
 * @Date 2025/7/7 2:19
 * @Version 1.0
 */

@Service
public class UserAuthService {
    @Resource
    private UserAuthMapper userAuthMapper;

    public UserAuth findByTypeAndOpenId(String authType, String openId) {
        return userAuthMapper.selectOne(new LambdaQueryWrapper<UserAuth>()
                .eq(UserAuth::getAuthType, authType)
                .eq(UserAuth::getOpenId, openId));
    }

    public void createUserAuth(Long userId, String authType, String openId, String nickname, String avatar) {
        UserAuth userAuth = new UserAuth();
        userAuth.setUserId(userId);
        userAuth.setAuthType(authType);
        userAuth.setOpenId(openId);
        userAuth.setNickname(nickname);
        userAuth.setAvatar(avatar);
        userAuthMapper.insert(userAuth);
    }
}
